package com.sysware.mymodule.controller;

import com.sysware.mymodule.entity.DataObject;
import com.sysware.mymodule.service.DataObjectService;
import com.sysware.mymodule.dto.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/mymodule")
@Api(tags = "xx模块API接口列表")
public class MyModuleController {

    @Autowired
    DataObjectService dataObjectService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @PostMapping("dataobject/create")
    @ApiOperation(value = "数据列表查询")
    public Response create(@ApiParam(value = "名称", required = true) @RequestParam String name,
                           @ApiParam(value = "描述") @RequestParam(required = false) String desc){
        dataObjectService.insert(name, desc);
        return new Response().success("1");
    }

    @GetMapping("dataobject/query")
    @ApiOperation(value = "数据列表查询")
    public Response queryDatas(@ApiParam(value = "名称", required = true) @RequestParam String name) {
        Response response = new Response();
        Page<DataObject> dataObjectPage = dataObjectService.getDataObjectByPage(name, 0, 10);
        response.setData(dataObjectPage.getContent());
        response.setCount(dataObjectPage.getTotalElements());
        logger.info("queryDataLocation");
        return response;
    }

}
